import { PatientsItem } from '@/interfaces/patients'
import type { ProColumns } from '@ant-design/pro-components';
import { Button } from 'antd';
import showDeleteConfirm from '@/utils/deleteConfirm';
import { deleteEntryExam } from '@/services/entryExam'
import WithAuthComp from '@/components/WithAuthComp';
import { ROLE } from '@/common/const'

const getColumns: (dialogRef, setReadonly, setId, resultAddRef) => ProColumns<PatientsItem>[] = (dialogRef, setReadonly, setId, resultAddRef) => {
    return [
        {
            title: '胸牌号',
            dataIndex: 'patientnumber',
        },
        {
            title: '姓名',
            dataIndex: 'name',
        },
        {
            title: '监区',
            dataIndex: 'jq',
        },
        {
            title: '体检时间',
            key: 'showTime',
            dataIndex: 'tjDate',
            valueType: 'date',
            sorter: true,
            hideInSearch: true,
        },
        {
            title: '体检时间',
            dataIndex: 'tjDate',
            valueType: 'dateRange',
            hideInTable: true,
            search: {
                transform: (value) => {
                    return {
                        tjStartDate: value[0],
                        tjEndDate: value[1],
                    };
                },
            },
        },
        {
            title: '操作',
            valueType: 'option',
            key: 'option',
            width: 120,
            render: (text, record, _, action) => [
                <WithAuthComp authKey={[ROLE.YS, ROLE.HS, ROLE.ZL]}>
                    <Button
                        color="cyan"
                        size='small'
                        type='primary'
                        key="detail"
                        onClick={() => {
                            setReadonly(true)
                            setId(record.recordId)
                            dialogRef?.current?.showModelRef('体检详情');
                            // action?.startEditable?.(record.id);
                        }}
                    >
                        详情
                    </Button>
                </WithAuthComp>
                ,
                <WithAuthComp authKey={[ROLE.YS, ROLE.HS, ROLE.ZL]}>
                    <Button
                        size='small'
                        type='primary'
                        key="edit"
                        onClick={() => {
                            setReadonly(false)
                            setId(record.recordId)
                            dialogRef?.current?.showModelRef('编辑体检信息');
                        }}
                    >
                        编辑
                    </Button>
                </WithAuthComp>
                ,
                <WithAuthComp authKey={[ROLE.YS, ROLE.HS]}>
                    <Button
                        size='small'
                        type='primary'
                        key="result"
                        ghost
                        onClick={() => {
                            // setReadonly(false)
                            setId(record.recordId)
                            resultAddRef?.current?.showModelRef();
                        }}
                    >
                        体检结果
                    </Button>
                </WithAuthComp>,
                <WithAuthComp authKey={[ROLE.ADMIN]}>
                    <Button
                        size='small'
                        type="primary"
                        key="delete"
                        danger
                        onClick={() => {
                            showDeleteConfirm({ id: record.recordId, action, deleteApi: deleteEntryExam })
                        }}
                    >
                        删除
                    </Button>
                </WithAuthComp>
                ,
            ],
        },
    ];
}

export default getColumns;